home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / e / amigae33a.lha / E_v3.3a / Src.lha / Src / OOmodules / library / device.e < prev    next >
Text File  |  1996-02-03  |  7KB  |  352 lines

  1. /****** device/--background-- ******************************************
  2.  
  3.     PURPOSE
  4.    The basic object for usage of devices. Will be changed when
  5.    the Stream is ready.
  6.  
  7.     CREATION
  8.    Back in February of 1995 by Gregor Goldbach
  9.  
  10.     HISTORY
  11.    Modifications by Trey van Riper.
  12.  
  13.     SEE ALSO
  14.    library
  15.  
  16. ******************************************************************************
  17.  
  18. History
  19.  
  20.  
  21. */
  22.  
  23.  
  24. OPT MODULE
  25. OPT OSVERSION=37
  26. OPT EXPORT
  27.  
  28. MODULE  'exec/devices',
  29.      'exec/io',
  30.      'exec/nodes',
  31.      'exec/ports',
  32.      'exec/devices',
  33.      'oomodules/library'
  34.  
  35. CONST SIZE_OF_BIGGEST_DEVICE_BLOCK=100, -> the size of the biggest device block
  36.    LONGEST_NAME=40
  37.  
  38. -> JEVR3 modification; moved 'name' to object 'library'.
  39.  
  40.  
  41. OBJECT device OF library
  42. /****** device/--device-- ******************************************
  43.  
  44.     NAME
  45.    device
  46.  
  47.     ATTRIBUTES
  48.    unit -- The unit of the device you want to use. If you don't know
  49.        of a special unit to specify when you work with a device, set
  50.        it to 0. Otherwise, as with the trackdisk.device for example,
  51.        set it to the unit you want to operate on. Think of a unit as
  52.        a 'sub-system' of that device.
  53.  
  54.    io -- Pointer to the io request structure used for this device.
  55.  
  56.    flags -- Special flags you set.
  57.  
  58.    lasterror -- You for convenience, this entry contains the last
  59.        error as in io.error.
  60.  
  61. ******************************************************************************
  62.  
  63. History
  64.  
  65.  
  66. */
  67.   unit
  68.   io:PTR TO io
  69.   flags
  70.   lasterror
  71. ENDOBJECT
  72.  
  73. -> JEVR3 addition; select() handles 'unit' and 'flag' options.
  74.  
  75. PROC select(opts,i) OF device
  76. /****** device/select ******************************************
  77.  
  78.     NAME
  79.    select() -- Select action via taglist
  80.  
  81.     SYNOPSIS
  82.    device.select()
  83.  
  84.     FUNCTION
  85.    Select an action upon initialization of the object. See
  86.    object/new() and object/select() for more information.
  87.  
  88.    Recognizes these items:
  89.      "unit" -- set unit of device
  90.  
  91.      "flag" -- set flags of device
  92.  
  93.     INPUTS
  94.    opts -- Optionlist
  95.  
  96.    i -- index of optionlist
  97.  
  98.     SEE ALSO
  99.    object/select()
  100. ******************************************************************************
  101.  
  102. History
  103.  
  104.  
  105. */
  106.  
  107. DEF item
  108.  
  109.   item:=ListItem(opts,i)
  110.  
  111.   SELECT item
  112.  
  113.     CASE "unit"
  114.    INC i
  115.    self.unit := ListItem(opts,i)
  116.  
  117.     CASE "flag"
  118.    INC i
  119.    self.flags := ListItem(opts,i)
  120.  
  121.     DEFAULT
  122.    i:=SUPER self.select(opts,i)
  123.  
  124.   ENDSELECT
  125. ENDPROC i
  126.  
  127. -> JEVR3 modification; no more options (new() handles that).  Changed the
  128. -> error handling a little bit.
  129.  
  130. PROC open() OF device HANDLE
  131. /****** device/open ******************************************
  132.  
  133.     NAME
  134.    open() -- Open a device with given attributes.
  135.  
  136.     SYNOPSIS
  137.    device.open()
  138.  
  139.     FUNCTION
  140.    Open a device with the attributes set.
  141.  
  142.     RETURNS
  143.    TRUE if the device could be opened.
  144.  
  145.     EXCEPTIONS
  146.    May raise "dev" with exceptioninfo
  147.  
  148.      {msgportfail} - CreateMsgPort() failed
  149.      {ioreqfail}     - CreateIORequest() failed
  150.      {opendev}  - OpenDevice() failed
  151.  
  152.     SEE ALSO
  153.    close(), select()
  154. ******************************************************************************
  155.  
  156. History
  157.  
  158.  
  159. */
  160. DEF ioreq=0:PTR TO io,
  161.     meinport:PTR TO mp,
  162.     fehler=0
  163.  
  164.   IF self.io THEN RETURN TRUE  -> JEVR3 modification.. reduce redundancy
  165.  
  166. ->try to open a no-name message port
  167.  
  168.   meinport := CreateMsgPort()
  169.   IF (meinport = NIL) THEN Throw("dev",{msgportfail})
  170.  
  171. ->try to create an iorequest
  172.  
  173.   ioreq := CreateIORequest(meinport, SIZE_OF_BIGGEST_DEVICE_BLOCK)
  174.   IF (ioreq = NIL) THEN Throw("dev",{ioreqfail})
  175.  
  176. ->try to open the device
  177.  
  178.   fehler := OpenDevice(self.identifier,self.unit,ioreq,self.flags)
  179.   IF(fehler)
  180.     Throw("dev",{opendev})
  181.   ELSE
  182.     self.io := ioreq
  183.     RETURN TRUE
  184.   ENDIF
  185.  
  186. -> EXCEPT handling by JEVR3
  187.  
  188. EXCEPT DO
  189.  IF ioreq THEN DeleteIORequest(ioreq)
  190.  IF meinport THEN DeleteMsgPort(meinport)
  191.  ReThrow()
  192. ENDPROC FALSE
  193.  
  194. -> JEVR3 modification; added IF statement
  195.  
  196. PROC close() OF device
  197. /****** device/close ******************************************
  198.  
  199.     NAME
  200.    close() -- Close a device if open.
  201.  
  202.     SYNOPSIS
  203.    device.close()
  204.  
  205.     FUNCTION
  206.    Closes the device and frees allocated resources.
  207.  
  208.     SEE ALSO
  209.    open()
  210. ******************************************************************************
  211.  
  212. History
  213.  
  214.  
  215. */
  216.   IF self.io
  217.    CloseDevice(self.io)
  218.    DeleteIORequest(self.io)
  219.    DeleteMsgPort(self.io.mn::mn.replyport)
  220.   ENDIF
  221. ENDPROC
  222.  
  223. PROC end() OF device
  224. /****** device/end *****************************************
  225.  
  226.     NAME
  227.    end() -- Frees allocated resources.
  228.  
  229.     SYNOPSIS
  230.    device.end()
  231.  
  232.     FUNCTION
  233.    Frees allocated resources of the object, that includes closing it.
  234.    Automatically called when ENDing the object.
  235.  
  236. ******************************************************************************
  237.  
  238. History
  239.  
  240.  
  241. */
  242.   self.close()
  243. ENDPROC
  244.  
  245. PROC doio() OF device
  246. /****** device/doio ******************************************
  247.  
  248.     NAME
  249.    doio() -- Perform a DoIO().
  250.  
  251.     SYNOPSIS
  252.    device.doio()
  253.  
  254.     FUNCTION
  255.    Perform exec.library's DoIO() on the io request.
  256.  
  257.     SEE ALSO
  258.    exec/DoIO()
  259. ******************************************************************************
  260.  
  261. History
  262.  
  263.  
  264. */
  265.   IF self.io THEN DoIO(self.io)
  266. ENDPROC
  267.  
  268. PROC sendio() OF device
  269. /****** device/sendio ******************************************
  270.  
  271.     NAME
  272.    sendio() -- Perform a SendIO().
  273.  
  274.     SYNOPSIS
  275.    device.sendio()
  276.  
  277.     FUNCTION
  278.    Perform exec.library's SendIO() on the io request.
  279.  
  280.     SEE ALSO
  281.    exec/SendIO()
  282. ******************************************************************************
  283.  
  284. History
  285.  
  286.  
  287. */
  288.   IF self.io THEN SendIO(self.io)
  289. ENDPROC
  290.  
  291. PROC abortio() OF device
  292. /****** device/abortio ******************************************
  293.  
  294.     NAME
  295.    abortio() -- Perform a AbortIO().
  296.  
  297.     SYNOPSIS
  298.    device.abortio()
  299.  
  300.     FUNCTION
  301.    Perform exec.library's AbortIO() on the io request.
  302.  
  303.     SEE ALSO
  304.    exec/AbortIO()
  305. ******************************************************************************
  306.  
  307. History
  308.  
  309.  
  310. */
  311.   IF self.io THEN AbortIO(self.io)
  312. ENDPROC
  313.  
  314. PROC reset() OF device
  315. /****** device/reset ******************************************
  316.  
  317.     NAME
  318.    reset() -- Reset the device.
  319.  
  320.     SYNOPSIS
  321.    device.reset()
  322.  
  323.     FUNCTION
  324.    reset the device by sending the according command.
  325.  
  326. ******************************************************************************
  327.  
  328. History
  329.  
  330.  
  331. */
  332.   IF self.io
  333.     self.io::iostd.command := CMD_RESET
  334.     DoIO(self.io)
  335.   ENDIF
  336. ENDPROC
  337.  
  338. -> JEVR3 addition: strings for error messages.  These should change
  339. -> in the future whenever we develop a fairly comprehensive locale
  340. -> handling object for all our devices.  Sorry it's English for now.
  341.  
  342. msgportfail:
  343.  CHAR 'Couldn''t create message port.',0
  344. ioreqfail:
  345.  CHAR 'Couldn''t create i/o request.',0
  346. opendev:
  347.  CHAR 'Couldn''t open the device.',0
  348. /*EE folds
  349. -1
  350. 41 30 45 49 117 24 120 19 123 20 126 20 129 20 132 21 
  351. EE folds*/
  352.